
Partial Class Shared_Error
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
        If Not Context.Items("ECGERROR") Is Nothing Then
            Dim ex As Exception = Context.Items("ECGERROR")
            lblMessage.Text = ex.Message
            SetIcon(ex)
            errorPanel.Visible = True
        Else
            errorPanel.Visible = False
        End If

        MyBase.OnPreRender(e)
    End Sub

    Private Sub SetIcon(ByVal ex As Exception)
        If TypeOf ex Is Common.Errors.DBError Then
            imgIcon.ImageUrl = "~/App_Themes/Granite/Images/database_warning.png"
        ElseIf TypeOf ex Is Common.Errors.CriticalError Then
            imgIcon.ImageUrl = "~/App_Themes/Granite/Images/warning.png"
        ElseIf TypeOf ex Is Common.Errors.InformationError Then
            imgIcon.ImageUrl = "~/App_Themes/Granite/Images/comment_warning.png"
        ElseIf TypeOf ex Is Common.Errors.ValidationError Then
            imgIcon.ImageUrl = "~/App_Themes/Granite/Images/questionmark.png"
        ElseIf TypeOf ex Is Common.Errors.InputError Then
            imgIcon.ImageUrl = "~/App_Themes/Granite/Images/smile_sad.png"
        Else
            imgIcon.ImageUrl = "~/App_Themes/Granite/Images/cancel.png"
        End If
    End Sub
End Class
